package com.example.event_resource_java.commons.util;



import com.example.event_resource_java.commons.type.NullType;
import lombok.extern.slf4j.Slf4j;

import org.apache.commons.lang3.StringUtils;


import java.util.HashMap;
import java.util.Map;
import java.util.Random;

@Slf4j
public class StringUtil {

    public static boolean isNull(String s){
        return !notEmpty(s);
    }
    //不为空
    public static boolean notEmpty(String str){
                //StringUtils.isNotEmpty(str);
              return str != null && !"".equals(str);
           }

    public static boolean isNotNull(String s){
        if (StringUtils.isNotBlank(s)){
            if (s.equals(NullType.SELECT_NULL.getStr())){
                return false;
            }
        }
        return true;
    }

    public static String getRandomStringByLength(int length) {
        String base = "abcdefghijklmnopqrstuvwxyz0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(base.length());
            sb.append(base.charAt(number));
        }
        return sb.toString();
    }

    /**
     * 将Map字符串转换为Map
     * @param str Map字符串
     * @return Map
     */
    public static Map<String, String> mapStringToMap(String str) {
        str = str.substring(1, str.length() - 1);
        String[] strs = str.split(",");
        Map<String, String> map = new HashMap<String, String>();
        for (String string : strs) {
            String key = string.split("=")[0];
            String value = string.split("=")[1];

            // 去掉头部空格
            String key1 = key.trim();
            String value1 = value.trim();
            map.put(key1, value1);
        }
        return map;
    }

    public static long gettimeStamp(){
        return System.currentTimeMillis() / 1000;
    }

    public static String getPrepay(String prepay_id){
        return "prepay_id="+prepay_id;
    }




}
